package org.gruposp2p.dnie.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;

public class EventBusManager {
	
    private static EventBusManager instance;
    private HandlerManager handlerManager;

    private EventBusManager () {
        handlerManager = new HandlerManager (this);
    }

    /**
     * @return the instance of the class
     */
    public static EventBusManager getInstance() {
        if (instance == null) {
            instance = new EventBusManager();
        }
        return instance;
    }

    public void registerToVotingOptionChange(final OptionChangeHandler handler) {
        handlerManager.addHandler(OptionChangeEvent.getType(), handler);
    }

    public void registerToDocumentToSignChange(final DocumentToSignChangeHandler handler) {
        handlerManager.addHandler(DocumentToSignChangeEvent.getType(), handler);
    }

    public void registerToSearchDocumentsChange(final SearchDocumentChangeHandler handler) {
        handlerManager.addHandler(SearchDocumentChangeEvent.getType(), handler);
    }
    
    public void registerToMostSignedDocumentChange(final MostSignedDocumentChangeHandler handler) {
        handlerManager.addHandler(MostSignedDocumentChangeEvent.getType(), handler);
    }    

    public void registerToUserSignedDocumentChange(final UserSignedDocumentChangeHandler handler) {
        handlerManager.addHandler(UserSignedDocumentChangeEvent.getType(), handler);
    }    

    public void registerToUserUploadedDocumentChange(final UserUploadedDocumentChangeHandler handler) {
        handlerManager.addHandler(UserUploadedDocumentChangeEvent.getType(), handler);
    }

    public void registerToStatisticChange(final StatisticChangeHandler handler) {
        handlerManager.addHandler(StatisticChangeEvent.getType(), handler);
    }

    public void fireEvent(GwtEvent event){
        handlerManager.fireEvent(event);
    }

}
